﻿using UnityEngine;
using System;
using System.Collections;
using System.IO;

/// <summary>
/// Classe chamada ao se clicar em 'Load Game'.
/// </summary>
public class Game_Load {
	
	#region Singleton
	private Game_Load(){}
	
	private static Game_Load instance;
	
	public static Game_Load getInstance()
	{
		if (instance == null)
			instance = new Game_Load();
		
		return instance;
	}
	#endregion
	
	public int LoadGame()
	{		
		Game_Directory gd =  Game_Directory.getInstance();
		
		StreamReader reader = new StreamReader(gd.PathString);
		
		string readed = reader.ReadToEnd();
		
		//Se está escrito alguma coisa no txt.
		if (readed != null)
		{
			int saveGameLength = Game_Save.getInstance().FileText.Length;
			string lvl = readed.Substring(saveGameLength, readed.Length - saveGameLength);
			int level = Convert.ToInt16(lvl);
			
			Game_Directory.getInstance().ReachedPhase = level;
		
			reader.Close();		
		}	
		
		return Game_Directory.getInstance().ReachedPhase;
	}
}